/*
This class draws a container in the selected screen.
*/

function DrawnContainer( screen, x, y, width, postits, containerType ) {
    var area = screen.appendElement( "<div enabled=\"true\" x=\""+x+"\" y=\""+y+"\" width=\""+width+"\" height=\""+(21+2+((20+44+2)*postits))+"\"></div>" );
    var src;
    var self = this;

    src = "resources\\container\\barraDeTitulo.png";
    this.frameTop = area.appendElement( " <div enabled=\"true\" x=\"0\" y=\"0\" width=\""+width+"\" height=\"21\" background=\""+src+"\"></div> " );

    if (containerType >= PREFERENCES) {
        src = "resources\\container\\bolinhaDosTitulos.png";
        this.titleDot = area.appendElement( " <div enabled=\"true\" x=\"10\" y=\"8\" width=\"6\" height=\"6\" background=\""+src+"\"></div> " );
    }
    else {
        src = "resources\\container\\botaoAddPostIt.png";
        this.buttonAddPost = area.appendElement( "<div enabled=\"true\" x=\"5\" y=\"5\" width=\"12\" height=\"12\" background=\""+src+"\"></div> " );
        this.buttonAddPost.onmouseover = function() { self.buttonAddPost.background = "resources\\container\\botaoAddPostItPorCima.png"; };
        this.buttonAddPost.onmouseout = function() { self.buttonAddPost.background = "resources\\container\\botaoAddPostIt.png"; };
        this.buttonAddPost.onclick = function() {
            showAddPost( self.containerType );
        };
        this.buttonAddPost.tooltip = TOOLTIP_ADDPOST;
    }
    
    src = "resources\\container\\setaParaCima.png";
    this.scrollUp = area.appendElement(" <div enabled=\"true\" x=\""+(width-16-2)+"\" y=\"5\" width=\"16\" height=\"14\" background=\""+src+"\"></div> ");
    this.scrollUp.onmouseup = function() { self.scrollUp.background = "resources\\container\\setaParaCima.png"; };
    this.scrollUp.onmousedown = function() { self.scrollUp.background = "resources\\container\\setaParaCimaApertada.png"; };
    this.scrollUp.onclick = function() {
        //TODO scroll up
        parameters.scrollOn = self;
        scrollUp();
    };
    
    src = "resources\\container\\setaParaBaixo.png";
    this.scrollDown = area.appendElement(" <div enabled=\"true\" x=\""+(width-16-16-2)+"\" y=\"5\" width=\"16\" height=\"14\" background=\""+src+"\"></div> ");
    this.scrollDown.onmouseup = function() { self.scrollDown.background = "resources\\container\\setaParaBaixo.png"; };
    this.scrollDown.onmousedown = function() { self.scrollDown.background = "resources\\container\\setaParaBaixoApertada.png"; };
    this.scrollDown.onclick = function() {
        //TODO scroll down
        parameters.scrollOn = self;
        scrollDown();
    };
    
    this.titleLabel = area.appendElement(" <label enabled=\"true\" x=\"18\" y=\"3\" width=\""+(width-18-16-16-2)+"\" height=\"18\" color=\"#0071bc\" font=\"Tahoma\" size=\"9\" bold=\"true\"></label>");
    this.postItArea = area.appendElement(" <div x=\"1\" y=\""+(21)+"\" width=\""+(width-1-1)+"\" height=\""+(2+((20+44+2)*postits))+"\"></div> ");
    
    if (containerType==TODO)
        this.titleLabel.innerText = SCRUM_TODO;
    else if (containerType==DOING)
        this.titleLabel.innerText = SCRUM_DOING;
    else if (containerType==IMPEDED)
        this.titleLabel.innerText = SCRUM_IMPEDED;
    else if (containerType==DONE)
        this.titleLabel.innerText = SCRUM_DONE;
    else if (containerType==PREFERENCES)
        this.titleLabel.innerText = MENU_PREFERENCES;
    else if (containerType==COLORS)
        this.titleLabel.innerText = MENU_COLORS;
    else if (containerType==BURNDOWN)
        this.titleLabel.innerText = SCRUM_BURNDOWN;
    
    this.containerType = containerType;
    this.area = area;
    
    this.posts = []; // Scroll through these displayed/hidden posts (set later)
    this.viewPost = 0; // Scrolling indicator
    this.displayedPosts = postits;
    
    if (containerType>=PREFERENCES) {
        this.scrollDown.visible = false;
        this.scrollUp.visible = false;
    }
    else {
    
        this.area.onmouseover = function() {
            parameters.scrollOn = self;
        };
    
    }
}

/*
    DrawnContainer.resize( new y pos, new width, ammount of post-its displayed )
*/
DrawnContainer.prototype.resize = function(x, y, width, postits) {
    this.area.x = x;
    this.area.y = y;
    this.area.width = width;
    this.area.height = (21+2+((20+44+2)*postits));
    this.frameTop.width = width;
    this.scrollUp.x = (width-16-2);
    this.scrollDown.x = (width-16-16-2);
    this.titleLabel.width = (width-18-16-16-2);
    this.postItArea.width = (width-1-1);
    this.postItArea.height = ( 2 + ((20+44+2)*postits) );
    this.displayedPosts = postits;
};